package com.example.blogother.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sun.source.doctree.IndexTree;
import com.xpd.blog.bean.Article;
import com.xpd.blog.bean.Favorite;
import org.apache.ibatis.annotations.*;
import org.hibernate.validator.constraints.NotEmpty;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xpd
 * @since 2024-09-29
 */
public interface FavoriteMapper extends BaseMapper<Favorite> {
    @Select("select * from favorite where usid=#{usid} and aid=#{aid}")
    Favorite selectByUsidAndId(@Param("usid") int usid,@Param("aid") int aid);

    @Delete("delete from favorite where usid=#{usid} and aid=#{aid}")
    int delFavByusidAndId(@Param("usid") int usid,@Param("aid") int aid);

    //查看自己的收藏
    @Results(id="rm1",value = {
            @Result(column = "id",property = "id",id=true),
            @Result(column = "aid",property = "aid"),
            @Result(column = "aid",property = "article",one = @One(
                    select = "selectByAid"
            ))
    })
    @Select("select * from favorite where usid=#{usid} limit #{page},#{size}")
    List<Favorite> selectByUsidArticles(@Param("usid") int usid,@Param("page")int page,@Param("size") int size);
    @Select("select * from article where aid=#{aid}")
    Article selectByAid(int aid);

}
